package coml.jiyun.hp.day02.model;

import coml.jiyun.hp.day02.bean.Bean;
import coml.jiyun.hp.day02.net.HttpUtil;
import coml.jiyun.hp.day02.net.ReslutCallBack;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import io.reactivex.subscribers.ResourceSubscriber;

public class MainPageModel {

    public void getData(int page, ReslutCallBack<Bean>callBack){
        HttpUtil.getInstance()
                .getApiService()
                .getData2(page)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeWith(new ResourceSubscriber<Bean>() {
                    @Override
                    public void onNext(Bean bean) {
                        callBack.onSuccess(bean);
                    }

                    @Override
                    public void onError(Throwable t) {
                        callBack.onFail(t.toString());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }
}